<?php

namespace App\Models;

use Carbon\Carbon;

/**
 * App\Models\Login
 *
 * @property int $id
 * @property string $username 用户名
 * @property string $nickname 昵称
 * @property int $admin_id 管理员ID
 * @property string $ip 登录IP
 * @property string $address IP地址
 * @property \Illuminate\Support\Carbon|null $login_at
 * @method static \Illuminate\Database\Eloquent\Builder|Login newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Login newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Login query()
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereAdminId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereLoginAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereNickname($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Login whereUsername($value)
 * @mixin \Eloquent
 */
class Login extends Base{

    protected $table = 'logins';


    protected $fillable = [
        'id','username','nickname','admin_id','ip','address', 'login_at'
    ];

    public $timestamps = false;//关闭自动维护

    protected $dates = ['login_at'];


    /**
     * 获取列表
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @return mixed
     */
    protected function getList($params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['kwd']) && $params['kwd']) {
                    $query ->where('username','like','%' . $params['kwd'] . '%')
                        ->orWhere('nickname','like','%' . $params['kwd'] . '%')
                        ->orWhere('ip','like','%' . $params['kwd'] . '%');
                }
            })->orderBy('id', 'desc')->paginate(config('app.limit'));
        return $lists;
    }
}
